import Vue from 'vue'
import VueRouter from 'vue-router'
import Routers from './router'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: Routers
})

// 类似路由中间件，访问前进行相应操作
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    next({
      path: '/login',
      query: {
        // fullpath为访问目录，该步骤作用是登录成功后，访问原先请求目录
        redirect: to.fullPath
      }
    })
  } else {
    next()
  }
})

export default router
